// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   MapAnnotationAttributeExtractor.java

package org.springframework.core.annotation;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.*;
import org.springframework.util.ClassUtils;

// Referenced classes of package org.springframework.core.annotation:
//			AbstractAliasAwareAnnotationAttributeExtractor, AnnotationUtils

class MapAnnotationAttributeExtractor extends AbstractAliasAwareAnnotationAttributeExtractor
{

	MapAnnotationAttributeExtractor(Map attributes, Class annotationType, AnnotatedElement annotatedElement)
	{
		super(annotationType, annotatedElement, enrichAndValidateAttributes(attributes, annotationType));
	}

	public Map getSource()
	{
		return (Map)super.getSource();
	}

	protected Object getRawAttributeValue(Method attributeMethod)
	{
		return getSource().get(attributeMethod.getName());
	}

	protected Object getRawAttributeValue(String attributeName)
	{
		return getSource().get(attributeName);
	}

	private static Map enrichAndValidateAttributes(Map original, Class annotationType)
	{
		Map attributes = new HashMap(original);
		Map attributeAliasMap = AnnotationUtils.getAttributeAliasMap(annotationType);
		for (Iterator iterator = AnnotationUtils.getAttributeMethods(annotationType).iterator(); iterator.hasNext();)
		{
			Method attributeMethod = (Method)iterator.next();
			String attributeName = attributeMethod.getName();
			Object attributeValue = attributes.get(attributeName);
			if (attributeValue == null)
			{
				String aliasName = (String)attributeAliasMap.get(attributeName);
				if (aliasName != null)
				{
					Object aliasValue = attributes.get(aliasName);
					if (aliasValue != null)
					{
						attributeValue = aliasValue;
						attributes.put(attributeName, attributeValue);
					}
				}
			}
			if (attributeValue == null)
			{
				Object defaultValue = AnnotationUtils.getDefaultValue(annotationType, attributeName);
				if (defaultValue != null)
				{
					attributeValue = defaultValue;
					attributes.put(attributeName, attributeValue);
				}
			}
			if (attributeValue == null)
				throw new IllegalArgumentException(String.format("Attributes map [%s] returned null for required attribute [%s] defined by annotation type [%s].", new Object[] {
					attributes, attributeName, annotationType.getName()
				}));
			Class returnType = attributeMethod.getReturnType();
			if (!ClassUtils.isAssignable(returnType, attributeValue.getClass()))
				throw new IllegalArgumentException(String.format("Attributes map [%s] returned a value of type [%s] for attribute [%s], but a value of type [%s] is required as defined by annotation type [%s].", new Object[] {
					attributes, attributeValue.getClass().getName(), attributeName, returnType.getName(), annotationType.getName()
				}));
		}

		return attributes;
	}

	public volatile Object getSource()
	{
		return getSource();
	}
}
